'use strict';

function compute_median(collection) {
  let temp =collection
  let average;
  function sortNumber(a,b)
  {   
      return a -b ;
  }
  temp.sort(sortNumber) 
  if(temp.length%2==0)
    {
      average=(temp[temp.length/2-1]+temp[temp.length/2+1-1])/2;
    }
  else 
    {
      average=temp[(temp.length+1)/2-1];
    }
  return average;
}

module.exports = compute_median;


